/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jschoolmanagerportable.model;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Transient;

/**
 *
 * @author Administrador
 */
@Entity
@Table(name = "ALUMNOS")
@NamedQueries({@NamedQuery(name = "Alumno.findById", query = "SELECT a FROM Alumno a WHERE a.id = :id"), @NamedQuery(name = "Alumno.findByNumerodelista", query = "SELECT a FROM Alumno a WHERE a.numerodelista = :numerodelista"), @NamedQuery(name = "Alumno.findByRut", query = "SELECT a FROM Alumno a WHERE a.rut = :rut"), @NamedQuery(name = "Alumno.findByNombres", query = "SELECT a FROM Alumno a WHERE a.nombres = :nombres"), @NamedQuery(name = "Alumno.findByApellidos", query = "SELECT a FROM Alumno a WHERE a.apellidos = :apellidos")})
public class Alumno implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);

    private static final long serialVersionUID = 1L;
    @Id
    @Column(name = "ID", nullable = false)
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "alumnos")
    @TableGenerator(name = "alumnos", table = "sequencer", pkColumnName = "class_name", valueColumnName = "class_id")
    private Integer id;
    @Column(name = "NUMERODELISTA", nullable = false)
    private int numerodelista;
    @Column(name = "RUT", nullable = false)
    private int rut;
    @Column(name = "NOMBRES", nullable = false)
    private String nombres;
    @Column(name = "APELLIDOS", nullable = false)
    private String apellidos;
    @OneToMany(cascade=CascadeType.ALL, mappedBy = "idalumno")
    private Collection<Nota> notaCollection;
    @JoinColumn(name = "IDCURSO", referencedColumnName = "ID")
    @ManyToOne
    private Curso idcurso;

    public Alumno() {
    }

    public Alumno(Integer id) {
        this.id = id;
    }

    public Alumno(Integer id, int numerodelista, int rut, String nombres, String apellidos) {
        this.id = id;
        this.numerodelista = numerodelista;
        this.rut = rut;
        this.nombres = nombres;
        this.apellidos = apellidos;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        Integer oldId = this.id;
        this.id = id;
        changeSupport.firePropertyChange("id", oldId, id);
    }

    public int getNumerodelista() {
        return numerodelista;
    }

    public void setNumerodelista(int numerodelista) {
        int oldNumerodelista = this.numerodelista;
        this.numerodelista = numerodelista;
        changeSupport.firePropertyChange("numerodelista", oldNumerodelista, numerodelista);
    }

    public int getRut() {
        return rut;
    }

    public void setRut(int rut) {
        int oldRut = this.rut;
        this.rut = rut;
        changeSupport.firePropertyChange("rut", oldRut, rut);
    }

    public String getNombres() {
        return nombres;
    }

    public void setNombres(String nombres) {
        String oldNombres = this.nombres;
        this.nombres = nombres;
        changeSupport.firePropertyChange("nombres", oldNombres, nombres);
    }

    public String getApellidos() {
        return apellidos;
    }

    public void setApellidos(String apellidos) {
        String oldApellidos = this.apellidos;
        this.apellidos = apellidos;
        changeSupport.firePropertyChange("apellidos", oldApellidos, apellidos);
    }

    public Collection<Nota> getNotaCollection() {
        return notaCollection;
    }

    public void setNotaCollection(Collection<Nota> notaCollection) {
        this.notaCollection = notaCollection;
    }

    public Curso getIdcurso() {
        return idcurso;
    }

    public void setIdcurso(Curso idcurso) {
        Curso oldIdcurso = this.idcurso;
        this.idcurso = idcurso;
        changeSupport.firePropertyChange("idcurso", oldIdcurso, idcurso);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Alumno)) {
            return false;
        }
        Alumno other = (Alumno) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return this.getApellidos() + " " + this.getNombres();
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }
}
